package com.example.controller;

import com.example.service.PdfToWordService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api")
public class PdfToWordController {

    private final PdfToWordService pdfToWordService;

    public PdfToWordController(PdfToWordService pdfToWordService) {
        this.pdfToWordService = pdfToWordService;
    }

    @PostMapping("/pdf-to-word")
    public ResponseEntity<String> convertPdfToWord(@RequestParam("file") MultipartFile file) {
        try {
            String outputFilePath = pdfToWordService.convertPdfToWord(file);
            return ResponseEntity.ok("文件已转换，保存路径：" + outputFilePath);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("转换失败: " + e.getMessage());
        }
    }
}
